R you serious? Teaching R programming to psych students

ECVP 2025

Meike Snijder-Steinhilber

University of Mainz

Introduction

My backgorund

Why Are We Here Today?

Goals

  • Exchange experiences, solutions, and challenges

  • Share some of my own lessons from teaching R

  • Explore possible approaches for your teaching hurdles

Limitations

  • Shaped strongly by my own experiences and by my lab’s context

  • Course settings & teaching styles are unique

  • First round of this workshop 🎉

Course structure

Challenges in Teaching R

Low student motivation due to

  • Lack of intrinsic interest in learning a programming language

  • No prior experience with programming

  • Unclear understanding of why this is a relevant skill

  • Expectation that it will be difficult to learn

Structural challenges

  • Students have very heterogeneous background knowledge

  • Inconsistent use of statistical software across labs and courses

  • Limited time available to teach R

  • Large number of students in each course

  • Missing resources to provide individual feedback

Getting to know each other

Please share briefly:

  • Your name, university, and current role

  • What you hope to gain from this workshop

  • One challenge (big or small) you or your lab experience when teaching R

Mindset

Personal lessons learned I

Structure

  • Set realistic teaching goals — and stick to them

  • Recognize that seminar structure strongly shapes student mindset

  • Provide sufficient support: resources, exercises, and constructive feedback

Communication

  • Be transparent and straightforward in communication

  • You set the tone — be aware of your influence

  • When reacting to background issues, explain openly when and why

Personal lessons learned II

Feedback & change:

  • Refine the course each semester (step by step)

  • Try new approaches; don’t repeat what didn’t work

  • Always seek feedback (from the whole class, in presence)

  • Feedback can hurt, share your experience with others

  • Take feedback seriously, but always consider the context

    • What caused it? What can I do to improve the situation?
  • Small adjustments can make a big difference

Teaching R means teaching a language

  • Syntax = grammar

  • Functions = vocabulary

  • Practice, practise, practise, ….

  • Do not forget to teach all of the basics

Balance the three key skills:

  • Reading code
  • Debugging (learning to help yourself)
  • Writing code

Design exercises with intention:

  • Order tasks by difficulty and prior knowledge
  • Match exercise types to specific skills
  • Mix very simple with more complex tasks

Programming means failing

“Experienced programmers don’t fail less — they just recover faster.”

  • Normalize failure
    • e.g., debug code live, mention common errors
  • Encourage self-help strategies first
    • Demonstrate practical debugging techniques
    • How do I read package documentations?

Increasing student motivation

Connect to relevance

  • Show examples of what students will be able to do by the end of the course
  • Highlight how R is needed for projects, research, and the curriculum
  • Show the broader potential of R beyond statistics
  • Use diagnostic or test questions to give students with prior knowledge realistic feedback on their level

Make it “fun”

  • Playful or surprising examples
    • e.g., art with ggplot, scatterplot dinosaurs
  • Interesting themes (even fun column names can help)

Support motivation through feedback

  • Timely, constructive, and encouraging feedback

Trade off teaching improvements vs work-load

  • little time & resources: start with small improvements

  • change the system instead of your workload

    • ask for an student assistance
    • collaborate with other teachers
    • teaching funds
    • new concepts: students feedback the code from each other
  • external (free & online) resources:

    • AI, software package, online tutorial, …

R basics

Foundations

  • Variables
  • Data types
  • Comments vs. code
  • Missing values (important for error messages)
  • Functions & arguments
  • Reading and writing data sets

Working with R

  • R projects
  • R scripts & R Markdown
  • R packages (Who writes R packages?)

Programming skills

  • Flexible vs. hard coding
  • Control structures (loops, if–else)
  • Understand error messages
  • debugging skills

Tidyverse

  • dplyr
  • ggplot2

And THEN, what you actually want to teach … 😉

Approaches and resources

Simulate your own data sets

Useful functions:

  • rnorm() – generate normal-distributed values
  • runif() – generate uniform random values
  • sample() – draw random samples
  • rbinom() – simulate binary outcomes
  • rexp(), rgamma(), etc. – simulate from other distributions
  • expand.grid() – create all combinations of factors

Useful packages:

Datasets archive:

Example: A quick data set

library(dplyr)
set.seed(42)
n <- 80
df <- tibble(
  subject = 1:n,
  age = sample(18:70, n, replace = TRUE),
  height  = rnorm(n, mean = 170, sd = 10),
  group   = sample(c("control", "treatment"), n, replace = TRUE)
) %>%
  mutate(
    score = rnorm(n, mean = ifelse(group == "treatment", 75, 70), sd = 5),
    response = rnorm(n, mean = 50, sd = 10)
  )

df %>% head()
# A tibble: 6 × 6
  subject   age height group     score response
    <int> <int>  <dbl> <chr>     <dbl>    <dbl>
1       1    66   156. control    73.0     36.2
2       2    54   174. control    77.2     70.5
3       3    18   162. control    65.0     60.2
4       4    42   184. treatment  77.3     49.7
5       5    27   166. control    70.4     57.0
6       6    53   177. control    74.5     40.3

Example: Correlated data

library("MASS")
set.seed(123)

# Define the mean vector
mean_vector <- c(0, 2, 1.8)

# Define the covariance matrix
cov_matrix <- matrix(c(
  1.00, 0.22, 0.10,
  0.22, 1.00, 0.80,
  0.10, 0.80, 1.00
), nrow = 3, byrow = TRUE)

# Generate n correlated random numbers
n <- 200
correlated_data <- mvrnorm(n, mu = mean_vector, Sigma = cov_matrix)

# Convert to a data frame and add column names
correlated_data <- data.frame(correlated_data)
names(correlated_data) <- c("fitness_level", "sport", "health")

# Calculate the correlations
round(cor(correlated_data), 2)
              fitness_level sport health
fitness_level          1.00  0.24   0.08
sport                  0.24  1.00   0.79
health                 0.08  0.79   1.00

Constructive Alignment

Teaching, learning, and assessment should all point in the same direction.

Intended learning outcomes

  • What should students be able to do?
  • What specific R skills should students be able to demonstrate?
  • e.g., import a dataset, run a regression, visualize results

Teaching & learning activities

  • How will they practice and engage with the content?
  • e.g., exercises at home, debugging code from other students, projects with real data)

Assessment

  • How will they demonstrate achievement of the outcomes?
  • e.g., open book exams, oral explanations, …

Constructive Alignment – Background

  • Developed by John Biggs (1996)
  • Based on the idea that students construct their own learning
  • The role of the teacher: design learning environments that support this process
  • Alignment means:
    • Learning outcomes define what students should achieve
    • Teaching activities give opportunities to practice
    • Assessment measures achievement of outcomes

Alternative exams

Open-book exams

  • Debug or correct given code
  • Extend existing scripts with new functionality
  • Explain what code does (or why it fails)
  • Interpret error messages
  • Use R’s help system to solve a task with a new function

Data science contest

  • Students have to analyze a (simulated) dataset
    • use personas to create variability
    • teaches also the meaning of QRPs & p-hacking
  • Students compete to produce the best talk/analysis/visualization
  • Students have to detect the “bad sheeps”
  • Encourages creativity, real-world problem-solving, and communication of results

Flipped Classroom – The Concept

Traditional order is reversed:

  • Students first engage with new material at home (videos, readings, tutorials)
  • Class time: practice, discussion, problem-solving
  • Emphasizes active learning rather than passive listening
  • Teacher role shifts from “lecturer” to facilitator/coach

Useful when:

  • Content can be learned at different paces
  • Class time is valuable for collaboration and feedback

Success factors:

  • Clear, well-structured pre-class materials
  • Accountability (e.g., small quizzes, short reflections)
  • In-class activities tightly linked to pre-class work

Flipped Classroom – Challenges

Students may be unprepared in class

High effort for instructors:

  • Preparing quality pre-class materials (texts, videos, exercises)
  • Designing effective in-class activities can be difficult

Requires a cultural shift:

  • Students expect “being taught” in class
  • Teachers must let go of content delivery
  • Teachers must be “strict”

Teaching materials

ChatGPT — students

Opportunities

  • Coding assistant
    • explanations, examples, debugging, feedback
  • Practice problems, synthetic datasets
  • Compare and critique AI vs. own solutions

Dangers

  • Cheating
  • AI usage prevents learning
  • No critical thinking

Ground rules

  • Specific to the seminar
    • e.g., only valid if explicitly allowed, only for explanations
  • Only allow solutions taught in the course

Explicit usage

  • Use AI for some homework explicitly
    • Warning: only in later stages
  • Live demos in class
    • evaluating AI answers
  • Critical thinking
    • correctness, efficiency, relevance

ChatGPT — teachers

  • Efficiency first
    • save time for what matters most (teaching & feedback)
  • Friendlier, more constructive feedback phrasing
  • More content
    • Generate exercises, code examples, explanations
  • Alternative explanations (multiple ways to explain)
  • Adapt exercises to different levels (beginner vs advanced)

R package: learnr

Concept


  • R package for interactive, self-paced tutorials

  • in R Markdown (.Rmd)

  • create you own shiny apps

    • code exercises
    • quizzes
    • hints/solutions
    • immediate feedback
  • supports flipped classroom

  • increase at home exercises

  • helps with automatic feedback

  • visit homepage

Pros & cons

Good for:

  • Lots of (smaller) guided practices

  • Many students in class/lecture

  • Quick, auto-graded checks

  • Pre- or post-class homework

  • Heterogeneous student background

Not ideal for

  • Large, complex projects with many valid paths

  • Heavy computation or huge datasets

  • Assessments needing complex, rich and individual feedback

  • No resources for Implementation

Default design

Simple examples I

Tutorial on quizzes

question_radio(
  "Is this a good question?",
  answer("yes", correct = TRUE),
  answer("no", message = 'This is a good question.')
)

Simple examples II

question_numeric(
 "What is pi rounded to 2 digits?",
 answer(3, message = "Don't forget to use the digits argument"),
 answer(3.14, correct = TRUE),
 allow_retry = TRUE,
 min = 3,
 max = 4,
 step = 0.01
)

Simple examples III

learnr::question_checkbox(
  "Select all the toppings that belong on a Margherita Pizza:",
  answer("tomato", correct = TRUE),
  answer("mozzarella", correct = TRUE),
  answer("basil", correct = TRUE),
  answer("extra virgin olive oil", correct = TRUE),
  answer("pepperoni", message = "Great topping! ... just not on a Margherita Pizza"),
  answer("onions"),
  answer("bacon"),
  answer("spinach"),
  random_answer_order = TRUE,
  allow_retry = TRUE,
  try_again = "Be sure to select all toppings!"
)

Otter as an example

Visit the Otter site

Workshop

Feedback

Contact


Software:




Contact:

E-Mail: meike.steinhilber@uni-mainz.de

GitHub: MeikeSteinhilber

Homepage: https://methoden.amd.psychologie.uni-mainz.de/steinhilber/











Appendix

  • post-hoc analyses of QRP